package cn.tedu.vod.controller;

import cn.tedu.commonUtils.R;
import cn.tedu.vod.utils.AliyunVodSDKUtils;
import cn.tedu.vod.utils.VodConstant;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

@Api("阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("/eduvod/video")
public class VideoController {
    @GetMapping("/get-play-auth/{videoId}")
    public R getVideoPlayAuth(@PathVariable("videoId") String videoId) throws Exception {

        //获取阿里云存储相关常量
        String accessKeyId = VodConstant.KEY_ID;
        String accessKeySecret = VodConstant.KEY_SECRET;

        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId,accessKeySecret);
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId);
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        response = client.getAcsResponse(request);
        String playAuth = response.getPlayAuth();
        System.out.println("playAuth:"+playAuth);

        //得到播放凭证

        //返回结果
        return R.ok().msg("获取凭证成功").data("playAuth", playAuth);
    }
}
